package com.lcache.core.zk;

/**
 * @program: LIM
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-04-14 18:00
 **/
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;

@Slf4j
public record ZookeeperConnector(CuratorFramework curatorFramework) {

    // 监听 /ws/nodes/ 路径下的所有子节点变化
    public void watchNodes(String path, PathChildrenCacheListener listener) throws Exception {
        PathChildrenCache cache = new PathChildrenCache(curatorFramework, path, true);
        cache.getListenable().addListener(listener);
        cache.start();
        log.info("Started listening to path: " + path);
    }
}
